function parseUrlParams(url) {
  const reg = /([^&=]+)=([\w\W]*?)(&|$|#)/g
  const { search, hash } = new URL(url);
  const args = [search, hash];
  let obj = {};
  for (let i = 0; i < args.length; i++) {
    const str = args[i];
    if (str) {
      const s = str.replace(/#|\//g, '')
      const arr = s.split('?')
      if (arr.length > 1) {
        for (let i = 1; i < arr.length; i++) {
          // console.log(reg.exec(arr[i]))
          /**
           * [
              'foo=bar',
              'foo',
              'bar',
              '',
              index: 0,
              input: 'foo=bar',
              groups: undefined
            ]
           */
          const res = reg.exec(arr[i]);
          obj[res[1]] = decodeURIComponent(res[2]);
        }
      }
    }
  }
  console.log(obj);
  return obj;
}


// 测试用例, expect true
const stringify = JSON.stringify

console.log(stringify(parseUrlParams('https://foo.bar?foo=bar#/top')) === stringify({
  query: { foo: 'bar' },
  hash: {},
}))

console.log(stringify(parseUrlParams('https://foo.bar#/top?foo=bar')) === stringify({
  query: {},
  hash: { foo: 'bar' },
}))


console.log(stringify(parseUrlParams('https://foo.bar?foo=bar&foo=baz#/top')) === stringify({
  query: {
    foo: ['bar', 'baz']
  },
  hash: {},
}))

console.log(stringify(parseUrlParams('https://foo.bar/top?foo=bar&foo=baz#/top?foo=bar&foo=baz')) === stringify({
  query: {
    foo: ['bar', 'baz']
  },
  hash: {
    foo: ['bar', 'baz']
  },
}))